package com.guigu.tomcat.impl;

import com.guigu.tomcat.HttpSession;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class HttpSessionImpl implements HttpSession {
    //创建时间戳
    private long creationTime;
    //唯一标识
    private String id;
    //最后访问时间
    private long lastAccessedTime;
    //最长活动时间Tomcat的会话默认有效时间30分钟
    private int maxInactiveInterval;
    //属性集合
    private Map<String, Object> attributeMap = new HashMap<>();

    public HttpSessionImpl() {
        creationTime = System.currentTimeMillis();
        id = UUID.randomUUID().toString().replaceAll("-", "");
    }

    @Override
    public long getCreationTime() {
        return creationTime;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public long getLastAccessedTime() {
        return lastAccessedTime;
    }

    @Override
    public int getMaxInactiveInterval() {
        return maxInactiveInterval;
    }

    @Override
    public void invalidate() {

    }

    @Override
    public void setAttribute(String name, Object value) {
        attributeMap.put(name, value);
    }

    @Override
    public Object getAttribute(String name) {
        return attributeMap.get(name);
    }

    @Override
    public void removeAttribute(String name) {
        attributeMap.remove(name);
    }
}
